package com.tdzh.maimaiti.view;

import android.content.SharedPreferences;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.tdzh.maimaiti.R;

import java.util.List;
import java.util.Map;

/**
 * Created by hisou on 2016/5/11.
 */
public class DetailsAdapter extends BaseAdapter{

        private LayoutInflater mLayoutInflater;
        private List<Map<String, String>> dataList;

        public DetailsAdapter(LayoutInflater layoutInflater, List<Map<String, String>> dataList){
            this.mLayoutInflater = layoutInflater;
            this.dataList = dataList;
            // requestsSharedPreferences = GetLocalRequest.getLocalRequest();
        }

        private class ViewHolder {
            public TextView recommenderDetails;
            public TextView recommender;
        }

        @Override
        public int getCount() {
            return dataList.size();
        }

        @Override
        public Object getItem(int position) {
            return dataList.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View view = convertView;
            final ViewHolder holder;
            if (convertView == null) {
                view = mLayoutInflater.inflate(R.layout.request_item, parent, false);
                holder = new ViewHolder();
                holder.recommenderDetails = (TextView) view.findViewById(R.id.recommenderDetailsText);
                holder.recommender = (TextView) view.findViewById(R.id.recommender);
                view.setTag(holder);        // 给View添加一个格外的数据
            } else {
                holder = (ViewHolder) view.getTag(); // 把数据取出来
            }

            Map<String, String> map = dataList.get(position);
            holder.recommenderDetails.setText(map.get("details"));
            holder.recommender.setText(map.get("recommender"));

            return view;
        }
    }

